﻿using System;
using System.Web.Mvc;

namespace Sencha.Direct
{
	/// <summary>
	/// Enable compression on <see cref="DirectJsonResult"/>. Silently ignores other <see cref="ActionResult"/> types
	/// </summary>
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
	public class CompressJsonAttribute : FilterAttribute, IResultFilter
	{
		#region IResultFilter Members

		public void OnResultExecuted(ResultExecutedContext filterContext)
		{
			if (filterContext.Result is DirectJsonResult)
				(filterContext.Result as DirectJsonResult).EnableCompression = true;
		}

		public void OnResultExecuting(ResultExecutingContext filterContext)
		{

		}

		#endregion
	}
}
